<template>
	<view class="address">
		<view v-if="type==0">
			<view class="flexJusp" style="line-height:112rpx;border-bottom: 2rpx solid #F0F0F0;padding:0 20rpx;">
				<view>姓名</view>
				<input v-model="username" style="margin-top:36rpx;text-align: right;font-size:28rpx;height:40rpx;"
					placeholder-style="color: #999999;" placeholder="请输入联系人姓名" />
			</view>
			<view class="flexJusp" style="line-height:112rpx;border-bottom: 2rpx solid #F0F0F0;padding:0 20rpx;">
				<view>联系电话</view>
				<input maxlength="11" v-model="phone" type="number"
					style="margin-top:34rpx;text-align: right;font-size:28rpx;height:40rpx;"
					placeholder-style="color: #999999;" placeholder="请输入联系人电话" />
			</view>
			<view class="flexJusp" style="line-height:112rpx;border-bottom: 2rpx solid #F0F0F0;padding:0 20rpx;">
				<view>商家名称</view>
				<input v-model="shangname" style="margin-top:36rpx;text-align: right;font-size:28rpx;height:40rpx;"
					placeholder-style="color: #999999;" placeholder="请输入商家名称" />
			</view>
			<view class="flexJusp" style="line-height:112rpx;border-bottom: 2rpx solid #F0F0F0;padding:0 20rpx;">
				<view>所在地址</view>
				<picker mode="region" @change="bindPickerChange" :value="citys">
					<view v-if="province">{{province}} {{city}} {{area}}</view>
					<view style="color: #999999;" v-else>请选择省市区</view>
				</picker>
			</view>
			<view class="flexJusp" style="line-height:112rpx;border-bottom: 2rpx solid #F0F0F0;padding:0 20rpx;">
				<view>企业介绍</view>
				<input v-model="info" style="margin-top:34rpx;text-align: right;font-size:28rpx;height:40rpx;"
					placeholder-style="color: #999999;" placeholder="请输入企业介绍" />
			</view>
			<view style="border-bottom: 2rpx solid #F0F0F0;padding:0 20rpx 16rpx;">
				<view style="margin:30rpx 0 10rpx;">商家logo</view>
				<image @click="upImage" style="width:204rpx;height:196rpx;border-radius:10rpx;"
					:src="images ||'/static/image/02_10df.png'"></image>
			</view>
			<view style="padding:0 20rpx 16rpx;">
				<view style="margin:30rpx 0 10rpx;">营业执照</view>
				<image @click="upImages" style="width:204rpx;height:196rpx;border-radius:10rpx;"
					:src="imagex ||'/static/image/02_10df.png'"></image>
			</view>
			<view class="flex" style="padding:40rpx 0 0 64rpx;">
				<image @click="check =!check" v-if="check" style="width:28rpx;height:28rpx;margin:8rpx 10rpx 0 0;" src="/static/image/05_8dfsfd.png"></image>
				<image @click="check =!check" v-else style="width:28rpx;height:28rpx;margin:8rpx 10rpx 0 0;" src="/static/image/05_8df.png"></image>
				<view>已阅读并同意 <text style="color: #2089FF;" @click="agreement('yonghu')">《用户服务协议》</text> </view>
			</view>
			<view class="buttonx" @click="addAddress">认证信息</view>
		</view>
		<view v-if="type==1" style="text-align: center;">
			<image style="width:500rpx;margin:70rpx 0 10rpx;" mode="widthFix" :src="this.$loadImage('emptyFile')"></image>
			<view style="font-size: 32rpx;color: #000000;">审核中</view>
			<view class="buttons" @click="backs">确定</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				check:false,
				type: 0,
				city: '',
				citys: [],
				name: '',
				mobile: '',
				address: '',
				id: '',
				province: '',
				area: '',
				images: '',
				imagex: '',
				username: '',
				phone: '',
				shangname: '',
				info: '',
			};
		},
		onLoad(option) {},
		methods: {
			agreement(type){
				uni.navigateTo({
					url:'/pages_user/user/agreement/agreement?type='+type
				})
			},
			backs(){
				uni.navigateBack()
			},
			upImage() {
				var that = this
				uni.chooseImage({
					count: 1, //默认9
					sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
					sourceType: ['album', 'camera'], //从相册选择
					success: function(res) {
						that.$upShop('upload',res.tempFilePaths[0]).then(rex => {
							let arr = JSON.parse(rex.data)
							console.log(arr,'-----------')
							that.images = arr.fileName
						}).catch((e) => {
						});
					}
				})
			},
			upImages() {
				var that = this
				uni.chooseImage({
					count: 1, //默认9
					sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
					sourceType: ['album', 'camera'], //从相册选择
					success: function(res) {
						that.$upShop('upload',res.tempFilePaths[0]).then(rex => {
							let arr = JSON.parse(rex.data)
							console.log(arr,'-----------')
							that.imagex = arr.fileName
						}).catch((e) => {
						});
					}
				})
			},
			changes(e) {
				console.log(e, '--------')
			},
			getAddressInfo() {
				this.$httpapi('/api/getAddressInfo', 'POST', {
					id: this.id
				}).then(res => {
					this.defaults = res.data.defaultFlag
					this.area = res.data.area
					this.city = res.data.city
					this.address = res.data.address
					this.name = res.data.name
					this.mobile = res.data.phone
					this.province = res.data.province
					this.citys[this.province, this.city, this.area]
				})
			},
			bindPickerChange(e) {
				console.log(e, '---------')
				this.province = e.detail.value[0]
				this.city = e.detail.value[1]
				this.area = e.detail.value[2]
			},
			addressXuan() {
				var that = this
				uni.chooseLocation({
					success: (data) => {
						that.address = data.name;
					}
				})
			},
			addAddress() {
				if(!this.check) return this.$utils.showtt('请先阅读协议后进行操作')
				this.$httpapi('shangruzhu', 'POST', {
					username: this.username,
					phone: this.phone,
					shangname: this.shangname,
					address: this.province+','+this.city+','+this.area,
					info: this.info,
					logo: this.images,
					zhizhao: this.imagex,
				}).then(res => {
					uni.showToast({
						title: res.msg,
						duration: 1500,
						icon: 'none'
					});
					if (res.code == 200) {
						setTimeout(() => {
							const eventChannel = this.getOpenerEventChannel()
							eventChannel.emit('acceptDataFromOpenedPages', res.data);
							uni.navigateBack()
						}, 1500)
					}
				})
			}

		}
	}
</script>

<style lang="scss">
	.address {
		padding: 0 0 30rpx;

		.buttons {
			margin: 158rpx auto 0;
			text-align: center;
			width: 326rpx;
			height: 88rpx;
			border-radius: 44rpx;
			border: 2rpx solid #2089FF;
			color: #2089FF;
			line-height: 88rpx;
		}
		.buttonx {
			margin: 16rpx auto 0;
			text-align: center;
			width: 710rpx;
			height: 88rpx;
			background: linear-gradient(180deg, #2089FF 0%, #11ACEF 100%);
			border-radius: 44rpx;
			color: #FFFFFF;
			line-height: 88rpx;
		}
	}
</style>
